package com.ftg.learn.day09.pattern.factorypattern;

import com.ftg.learn.day08.Student;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 宠物工厂
 *
 * @author 布衣
 */
public class PetFactory{

    /**
     * 获取对象方法
     * @param petEnum
     * @return
     */
    public Pet getPet(PetEnum petEnum){
        switch (petEnum){
            case Cat:
                return new Cat();
            case Dog:
                return new Dog();
        }
        return null;
    }


    public Pet getPet(String name,double price,PetEnum petEnum){
        switch (petEnum){
            case Cat:
                return new Cat(name,price);
            case Dog:
                return new Dog(name,price);
        }
        return null;
    }


    public Pet getPet(String name,double price,Class<?extends Pet> c) throws InstantiationException, IllegalAccessException {
        return (Pet)c.newInstance();
    }

    public Object getAnyClass(Class c) throws InstantiationException, IllegalAccessException {
        return c.newInstance();
    }


    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        PetFactory p = new PetFactory();
        p.getPet("张三",200,Dog.class);
        Object anyClass = p.getAnyClass(String.class);
        Object a1 = p.getAnyClass(Student.class);
    }

}
